package com.myqm.controller.admin;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.myqm.dto.ResultResponse;
import com.myqm.pojo.weixin.User;
import com.myqm.pojo.weixin.Verified;
import com.myqm.pojo.weixin.query.QueryUser;
import com.myqm.service.weixin.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "管理用户")
@RestController
@RequestMapping(value = "/admin/user")
public class UserManagerController {

	@Autowired
	private UserService userService;
	
//	@ApiOperation(value="删除记录")
//	@DeleteMapping(value="/del")
//	public ResultResponse<Integer> delById(
//	@ApiParam(required=true,value="查询记录编号") @RequestBody Integer id) {
//		return new ResultResponse<Integer>(userService.delById(id));
//	}
//	
//	@ApiOperation(value="新增记录")
//	@PostMapping(value="/add")
//	@ApiParam(required = true, value = "记录值")
//	public ResultResponse<User> save(@Valid  @RequestBody User record) {
//	    if(userService.save(record)<=0)
//	        record=null;
//	    else
//	        record=userService.getById(record.getId());
//		return new ResultResponse<User>(record);
//	}
	
	@ApiOperation(value = "根据ID查询记录") 
	@PutMapping(value = "/get")
	public ResultResponse<User> getById(
			@ApiParam(required = true, value = "查询记录编号")
			@RequestBody @Valid Integer id) {
		return new ResultResponse<User>(userService.getById(id));
	}

	@ApiParam(required = true , value = "记录内容")
	@PutMapping(value = "/edit") 
	public ResultResponse<User> editById(@Valid @RequestBody User record) {
		if(userService.edit(record)<=0)
	        record=null;
	    else
	        record=userService.getById(record.getId());
		return new ResultResponse<User>(record);
	}
	
	@ApiParam(required = true , value = "记录内容")
	@PutMapping(value = "/isverify") 
	public ResultResponse<Integer> isverify(@Valid @RequestBody Verified record){
		return new ResultResponse<Integer>(userService.verified(record));
	}

	@ApiOperation(value = "详细列表查询") 
	@PostMapping("/list")
	public ResultResponse<PageInfo<User>> list(
			@ApiParam(required = false, value = "查询参数")
			@Valid @RequestBody QueryUser param){
		return new  ResultResponse<PageInfo<User>>
			(userService.list(param.getPageNum(), param.getPageSize(),param));
	}
}
